package org.lanqiao.dxzf.controller.bill;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.lanqiao.dxzf.entity.Page;
import org.lanqiao.dxzf.entity.ResultBill;
import org.lanqiao.dxzf.service.bill.BillService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;



@Controller
@RequestMapping
public class BillController {
	
	@Resource
	BillService billService;
	
	//@RequestMapping("/bill_list.do")
	public String bill_list(Page page, HttpServletRequest request){
		//查询出的list数据
		List<ResultBill> lb = billService.getAllBills();
	    //刚开始的页面为第一页
	    if (page.getCurrentPage() == null){
	        page.setCurrentPage(1);
	    } else {
	        page.setCurrentPage(page.getCurrentPage());
	    }
	    //设置每页数据为十条
	    page.setPageSize(5);
	    //每页的开始数
	    page.setStar((page.getCurrentPage() - 1) * page.getPageSize());
	    //list的大小
	    int count = lb.size();
	    //设置总页数
	    page.setTotalPage(count % 5 == 0 ? count / 5 : count / 5 + 1);
	    //对list进行截取
	    page.setDataList(lb.subList(page.getStar(),count-page.getStar()>page.getPageSize()?page.getStar()+page.getPageSize():count));
	    //设置作用域
	    request.setAttribute("paging", page);   
		return "bill/bill_list";
	}
	@RequestMapping("/bill_list.do")
	public String bill_search(Page page,HttpServletRequest request,ResultBill rb,Model model) {
		List<ResultBill> lr = billService.getBillByCon(rb);
		//刚开始的页面为第一页
	    if (page.getCurrentPage() == null){
	        page.setCurrentPage(1);
	    } else {
	        page.setCurrentPage(page.getCurrentPage());
	    }
	    //设置每页数据为十条
	    page.setPageSize(5);
	    //每页的开始数
	    page.setStar((page.getCurrentPage() - 1) * page.getPageSize());
	    //list的大小
	    int count = lr.size();
	    //设置总页数
	    page.setTotalPage(count % 5 == 0 ? count / 5 : count / 5 + 1);
	    //对list进行截取
	    page.setDataList(lr.subList(page.getStar(),count-page.getStar()>page.getPageSize()?page.getStar()+page.getPageSize():count));
	    //设置作用域
	    model.addAttribute("paging", page);  
	    
		return "bill/bill_list";
	}
	@RequestMapping("bill_item.do")
	public String bill_item(Page page, HttpServletRequest request,ResultBill rb,Model model){
		//查询出的list数据
		List<ResultBill> lb = billService.getItemByBill(rb);//表格信息
		List<ResultBill> lib = billService.getItemBybid(rb);//页头信息
	    //刚开始的页面为第一页
	    if (page.getCurrentPage() == null){
	        page.setCurrentPage(1);
	    } else {
	        page.setCurrentPage(page.getCurrentPage());
	    }
	    //设置每页数据为十条
	    page.setPageSize(5);
	    //每页的开始数
	    page.setStar((page.getCurrentPage() - 1) * page.getPageSize());
	    //list的大小
	    int count = lb.size();
	    //设置总页数
	    page.setTotalPage(count % 5 == 0 ? count / 5 : count / 5 + 1);
	    //对list进行截取
	    page.setDataList(lb.subList(page.getStar(),count-page.getStar()>page.getPageSize()?page.getStar()+page.getPageSize():count));
	    //设置作用域
	    request.setAttribute("paging", page);   
	    model.addAttribute("item", page);
	    request.setAttribute("lib", page);
		return "bill/bill_item";
	}
	@RequestMapping("bill_service_detail.do")
	public String bill_service(Page page, HttpServletRequest request,ResultBill rb,Model model){
		//查询出的list数据
		List<ResultBill> lb = billService.getDetailByItem(rb);//表格信息
		List<ResultBill> lib = billService.getDetailByrid(rb);//页头信息
	    //刚开始的页面为第一页
	    if (page.getCurrentPage() == null){
	        page.setCurrentPage(1);
	    } else {
	        page.setCurrentPage(page.getCurrentPage());
	    }
	    //设置每页数据为十条
	    page.setPageSize(5);
	    //每页的开始数
	    page.setStar((page.getCurrentPage() - 1) * page.getPageSize());
	    //list的大小
	    int count = lb.size();
	    //设置总页数
	    page.setTotalPage(count % 5 == 0 ? count / 5 : count / 5 + 1);
	    //对list进行截取
	    page.setDataList(lb.subList(page.getStar(),count-page.getStar()>page.getPageSize()?page.getStar()+page.getPageSize():count));
	    //设置作用域
	    request.setAttribute("paging", page);  
	    model.addAttribute("detail", page);
		return "bill/bill_service_detail";
	}
}
